package com.olah.user.dao;

import com.olah.common.entity.po.user.AddFriendConfig;
import com.olah.common.entity.po.user.Friend;
import com.olah.common.entity.po.user.QuestionAndAnswer;
import com.olah.common.entity.po.user.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface FriendDao {

    Integer updateQA(@Param("info") AddFriendConfig info);

    List<Friend> queryMyFriends(@Param("id") Integer id);

    @Select("SELECT usr_add_me FROM user WHERE usr_id = #{targetId}")
    Integer queryAddMethod(int targetId);

    @Update("UPDATE user SET usr_add_me = #{info.mode} WHERE usr_id = #{info.id}")
    Integer updateAddMethod(@Param("info") AddFriendConfig info);

    @Select("SELECT uq_question as question, uq_answer as answer FROM user_question WHERE uq_user_id = #{targetId}")
    List<QuestionAndAnswer> queryQuestions(int targetId);

    @Select("SELECT fri_note_name FROM friend_map WHERE fri_me = #{myId} AND fri_another = #{anotherId}")
    String noteName(Map<String, Integer> map);

    @Select("SELECT count(fri_id) FROM friend_map WHERE fri_me = #{myId} AND fri_another = #{anotherId}")
    int isFriend(Map<String, Integer> map);
}
